package com.lehecai.core.api.game;

import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.game.ItemStatus;
import com.lehecai.core.game.ItemType;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
 * 游戏物品
 * @author chirowong
 */
public class GameItem extends AbstractApiResultBean {
	
    public static final String GAME_ID = "game_id";
    public static final String ITEM_ID = "item_id";
    public static final String ITEM_TYPE = "item_type";
    public static final String ITEM_STATUS = "item_status";
    public static final String ITEM_SORT = "item_sort";
    public static final String ITEM_GROUP = "item_group";
    public static final String ITEM_GROUP_NAME = "item_group_name";
    public static final String ITEM_NAME = "item_name";
    public static final String ITEM_DES = "item_des";
    public static final String ITEM_IMAGE = "item_image";
    public static final String ITEM_RATE_CASH = "item_rate_cash";
    public static final String ITEM_RATE_CREDIT = "item_rate_credit";
    public static final String ITEM_MIN_UNIT = "item_min_unit";
    
	private String gameId;   		//游戏id
    private String itemId;    		//物品id
    private ItemType itemType;   	//物品类型
    private ItemStatus itemStatus; 	//物品状态
    private String itemSort;   		//物品排序
    private String itemGroup; 		//物品组别
    private String itemGroupName; 	//物品组名
    private String itemName;  		//物品名
    private String itemDes;     	//物品描述
    private String itemImage; 		//物品图片
    private String itemRateCash; 	//现金充值比例
    private String itemRateCredit; 	//彩贝充值比例
    private String itemMinUnit;		//最小充值额

    public static GameItem convertFromJSONObject(JSONObject object) {
        if (object == null) {
            return null;
        }
        GameItem item = new GameItem();
        item.gameId = getString(object, "game_id");
        item.itemId = getString(object, "item_id");
        item.setItemType(ItemType.getItem(getInt(object, "item_type")));
        item.setItemStatus(ItemStatus.getItem(getInt(object, "item_status")));
        item.itemSort = getString(object, "item_sort");
        item.itemGroup = getString(object, "item_group");
        item.itemGroupName = getString(object, "item_group_name");
        item.itemName = getString(object, "item_name");
        item.itemDes = getString(object, "item_des");
        item.itemImage = getString(object, "item_image");
        item.itemRateCash = getString(object, "item_rate_cash");
        item.itemRateCredit = getString(object, "item_rate_credit");
        item.itemMinUnit = getString(object, "item_min_unit");
        return item;
    }

    public static List<GameItem> convertFromJSONArray(JSONArray array) {
        if (array == null) {
            return null;
        }
        List<GameItem> list = new ArrayList<GameItem>();

        for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
            JSONObject object = (JSONObject) iterator.next();
            list.add(convertFromJSONObject(object));
        }
        return list;
    }


    public String getGameId() {
		return gameId;
	}

	public void setGameId(String gameId) {
		this.gameId = gameId;
	}

	public String getItemId() {
		return itemId;
	}

	public void setItemId(String itemId) {
		this.itemId = itemId;
	}

	public ItemType getItemType() {
		return itemType;
	}

	public void setItemType(ItemType itemType) {
		this.itemType = itemType;
	}

	public ItemStatus getItemStatus() {
		return itemStatus;
	}

	public void setItemStatus(ItemStatus itemStatus) {
		this.itemStatus = itemStatus;
	}

	public String getItemSort() {
		return itemSort;
	}

	public void setItemSort(String itemSort) {
		this.itemSort = itemSort;
	}

	public String getItemGroup() {
		return itemGroup;
	}

	public void setItemGroup(String itemGroup) {
		this.itemGroup = itemGroup;
	}

	public String getItemGroupName() {
		return itemGroupName;
	}

	public void setItemGroupName(String itemGroupName) {
		this.itemGroupName = itemGroupName;
	}

	public String getItemName() {
		return itemName;
	}

	public void setItemName(String itemName) {
		this.itemName = itemName;
	}

	public String getItemDes() {
		return itemDes;
	}

	public void setItemDes(String itemDes) {
		this.itemDes = itemDes;
	}

	public String getItemImage() {
		return itemImage;
	}

	public void setItemImage(String itemImage) {
		this.itemImage = itemImage;
	}

	public String getItemRateCash() {
		return itemRateCash;
	}

	public void setItemRateCash(String itemRateCash) {
		this.itemRateCash = itemRateCash;
	}

	public String getItemRateCredit() {
		return itemRateCredit;
	}

	public void setItemRateCredit(String itemRateCredit) {
		this.itemRateCredit = itemRateCredit;
	}

	public String getItemMinUnit() {
		return itemMinUnit;
	}

	public void setItemMinUnit(String itemMinUnit) {
		this.itemMinUnit = itemMinUnit;
	}
}
